﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Obligatorio2013.Modelo;

namespace Obligatorio2013.Pages
{
    public partial class CategoryForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((bool)Session["logged"] == true)
            {
                if (!Page.IsPostBack)
                {
                    if (Session["controller"] == null)
                    {
                        Session["controller"] = Sistema.Instance;
                    }

                }
            }
            else
            {
                Response.Redirect("~/Pages/Private/LoginForm.aspx");
            }

        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Pages/UserList.aspx", true);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Sistema system = Sistema.Instance;
            bool validateInfo = system.validateCategoryInfo(this.txtName.Text);

            if (validateInfo)
            {
                system.saveCategory(this.txtName.Text, this.txtKeys.Text);
            }
        }
    }
}